package com.qyhl.webtv.module_user.shop;

import com.qyhl.webtv.basiclib.utils.network.EasyHttp;
import com.qyhl.webtv.basiclib.utils.network.callback.SimpleCallBack;
import com.qyhl.webtv.basiclib.utils.network.exception.ApiException;
import com.qyhl.webtv.commonlib.entity.user.ShoppingOrderBean;
import com.qyhl.webtv.module_user.common.UserUrl;

import java.util.List;

public class ShopExchangeModel implements ShopExchangeContract.ShopExchangeModel {
    private ShopExchangePresenter mPresenter;

    public ShopExchangeModel(ShopExchangePresenter mPresenter) {
        this.mPresenter = mPresenter;
    }

    @Override
    public void getList(String phone, String page) {
        EasyHttp.get(UserUrl.GET_SHOP_ORDER_LIST)
                .params("phone", phone)
                .params("page", page)
                .execute(new SimpleCallBack<List<ShoppingOrderBean>>() {
                    @Override
                    public void onError(ApiException e) {
                        if (e.getCode() == 202) {
                            mPresenter.setError("暂无任何内容！", !page.equals("1"));
                        } else {
                            mPresenter.setError("请求出错，请重新获取！", !page.equals("1"));
                        }
                    }

                    @Override
                    public void onSuccess(List<ShoppingOrderBean> beanList) {
                        if (beanList != null && beanList.size() > 0) {
                            mPresenter.setList(beanList, !page.equals("1"));
                        } else {
                            mPresenter.setError("暂无任何内容！", !page.equals("1"));
                        }
                    }
                });
    }
}
